<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="theme-color" content="#3367D6"/>
  <link rel="apple-touch-icon" href="/icons-192.png">
  <link rel="manifest" href="/manifest.json">
  <link rel="stylesheet" href="/lib/google-code-prettify/themes/tomorrow-night.css">
  <script type="text/javascript" src="/lib/google-code-prettify/src/prettify.js"></script>
  
  <meta name="generator" content="Hexo 5.4.2">

  
    <meta name="description" content="觉宇宙之无穷，识盈虚之有数">
  

  

  
    <meta name="author" content="RocPengHua">
  

  

  

  <title>centos7搭建kafka集群 | 小鹏驿站</title>

  

  
    <link rel="shortcut icon" href="/favicon.ico">
  

  

  
<link rel="stylesheet" href="/css/style.css">

</head>
<body onload="PR.prettyPrint()">
  <div class="root-container">
    
<!-- header container -->
<header class="header-container post">
  
    <div class="post-image" style="background-image: url(&#39;https://api.lixingyong.com/api/images?postid=3799a5c6&amp;type=url&amp;itype=image&#39;)"></div>
  
  <!-- navbar -->
<nav class="navbar">
  <div class="navbar-content">
    <!-- logo -->
    <div class="navbar-logo">
      <a href="/">
        
          小鹏驿站
        
      </a>
    </div>
    <!-- link -->
    <div class="navbar-link">
      <div class="navbar-btn">
        <div></div>
        <div></div>
        <div></div>
      </div>
      <ul class="navbar-list">
        
              <li class="navbar-list-item">
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-home faa-shake" aria-hidden="true"></i>
                    首页
                  </span>
                </a>
                
              </li>
            
              <li class="navbar-list-item">
                <a href="/archives">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
                    归档
                  </span>
                </a>
                
              </li>
            
              <li class="navbar-list-item">
                <a href="/categories">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-folder faa-shake" aria-hidden="true"></i>
                    分类
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/categories/%E5%90%8E%E7%AB%AF/">
                          <i class="fa fa-etsy" aria-hidden="true"></i>
                          后端
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E5%89%8D%E7%AB%AF/">
                          <i class="fa fa-grav" aria-hidden="true"></i>
                          前端
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E8%BD%AF%E4%BB%B6/">
                          <i class="fa fa-key" aria-hidden="true"></i>
                          软件
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E7%AE%97%E6%B3%95/">
                          <i class="fa fa-glass" aria-hidden="true"></i>
                          算法
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">
                          <i class="fa fa-database" aria-hidden="true"></i>
                          数据库
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/">
                          <i class="fa fa-arrows-alt" aria-hidden="true"></i>
                          中间件
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E9%97%AE%E9%A2%98/">
                          <i class="fa fa-telegram" aria-hidden="true"></i>
                          问题
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E9%97%B2%E8%B0%88/">
                          <i class="fa fa-vcard" aria-hidden="true"></i>
                          闲谈
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li class="navbar-list-item">
                <a href="/tags">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-tags" aria-hidden="true"></i>
                    标签
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/tags/%E5%8A%A0%E5%AF%86/">
                          <i class="fa fa-wpexplorer" aria-hidden="true"></i>
                          加密
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/idea/">
                          <i class="fa fa-eercast" aria-hidden="true"></i>
                          idea
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/java/">
                          <i class="fa fa-coffee" aria-hidden="true"></i>
                          java
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/mysql/">
                          <i class="fa fa-database" aria-hidden="true"></i>
                          mysql
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/oracle/">
                          <i class="fa fa-database" aria-hidden="true"></i>
                          oracle
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/spring/">
                          <i class="fa fa-leaf" aria-hidden="true"></i>
                          spring
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/redis/">
                          <i class="fa fa-fire" aria-hidden="true"></i>
                          redis
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/mongodb/">
                          <i class="fa fa-database" aria-hidden="true"></i>
                          mongodb
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/rocketmq/">
                          <i class="fa fa-random" aria-hidden="true"></i>
                          rocketmq
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/kafka/">
                          <i class="fa fa-random" aria-hidden="true"></i>
                          kafka
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li class="navbar-list-item">
                <a href="/music">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-music" aria-hidden="true"></i>
                    音乐
                  </span>
                </a>
                
              </li>
            
              <li class="navbar-list-item">
                <a href="/links">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-link" aria-hidden="true"></i>
                    友链
                  </span>
                </a>
                
              </li>
            
              <li class="navbar-list-item">
                <a href="/about">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-signing" aria-hidden="true"></i>
                    关于
                  </span>
                </a>
                
              </li>
            
      </ul>
    </div>
  </div>
</nav>

  
  <span class="local-search local-search-google local-search-plugin" style="left: calc(50% - 200px);top: 0px;;position:absolute;z-index:2;">
      <input type="search" placeholder="小鹏驿站" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  
  

  
  

  
  

  
  

  
  
    <div class="header-content">
      <div class="post-text layout-block">
        <div class="layout-margin">
          <h1 class="title-wrap" title="觉宇宙之无穷，识盈虚之有数">centos7搭建kafka集群</h1>
          <h2 class="title-sub-wrap">
            <strong>RocPengHua</strong>
            <span>发布于</span>
            <time  class="article-date" datetime="2022-07-19T13:01:39.000Z" itemprop="datePublished">2022-07-19</time>
          </h2>
          <ul class="wrap-list dark">
  
    <li><a href="/categories/%E8%BD%AF%E4%BB%B6/">📒 软件</a></li>
  
</ul>
          <ul class="wrap-list dark">
  
    <li><a href="/tags/%E4%B8%AD%E9%97%B4%E4%BB%B6/">🏷️ 中间件</a></li>
  
    <li><a href="/tags/kafka/">🏷️ kafka</a></li>
  
</ul>
        </div>
      </div>
    </div>
  

  
  
  
</header>

    <!-- 文章 -->

<!-- 文章内容 -->
<div class="body-container">
  <article class="content-container layout-block post-container">
    <div class="widget-info">
      <section class="widget-author widget-item layout-margin content-padding--primary soft-size--large soft-style--box">
  <div class="widget-body">
    
      <img src="/images/p.jpg" class="soft-size--round soft-style--box" alt="RocPengHua">
    
    
      <h2>RocPengHua</h2>
    
    
      <p>天天向上</p>
    

    <div class="count-box">
      <div class="count-box--item">
        <svg class="icon icon-article" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M240.51564747 647.74217627h196.07203239c16.59071043 0 30.16492806-13.57421762 30.16492805-30.16492806V165.10332731c0-33.18142087-30.16492806-60.32985613-60.32985612-60.32985611H245.04038668C225.43318342 104.7734712 210.35071939 119.85593522 210.35071939 139.46313845V617.57724821c0 16.59071043 13.57421762 30.16492806 30.16492808 30.16492806z m663.62841731-452.47392089v482.63884894c0 33.18142087-27.14843525 60.32985613-60.32985612 60.32985613H180.18579134c-33.18142087 0-60.32985613-27.14843525-60.32985612-60.32985613V195.26825538c-49.77213131 0-90.49478418 40.72265287-90.49478417 90.49478417v452.4739209c0 49.77213131 40.72265287 90.49478418 90.49478417 90.49478417h286.56681657c16.59071043 0 30.16492806 13.57421762 30.16492807 30.16492807s13.57421762 30.16492806 30.16492805 30.16492806h90.49478418c16.59071043 0 30.16492806-13.57421762 30.16492805-30.16492806s13.57421762-30.16492806 30.16492807-30.16492807h286.56681657c49.77213131 0 90.49478418-40.72265287 90.49478417-90.49478417V285.76303955c0-49.77213131-40.72265287-90.49478418-90.49478417-90.49478417zM587.41232014 647.74217627h191.54729318c19.60720323 0 34.68966726-15.08246403 34.68966729-34.68966727V134.93839925c0-16.59071043-13.57421762-30.16492806-30.16492808-30.16492805H617.57724821c-30.16492806 0-60.32985613 27.14843525-60.32985612 60.32985611v452.4739209c0 16.59071043 13.57421762 30.16492806 30.16492805 30.16492806z" fill="currentColor"></path>
</svg>
        <span>118</span>
      </div>
      <div class="count-box--item">
        <svg class="icon icon-categories" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M900.3614811 257.09082106h-339.81629553l-67.96326003-101.9448889c-19.41807444-29.12711113-48.54518557-43.69066667-82.52681443-43.69066667H123.6385189c-53.39970333 0-97.09036999 43.69066667-97.09037113 97.09036999v582.54222222c0 53.39970333 43.69066667 97.09036999 97.09037113 97.09037002h776.7229622c53.39970333 0 97.09036999-43.69066667 97.09037113-97.09037002V354.18119104c0-53.39970333-43.69066667-97.09036999-97.09037113-97.09036998z m-97.09036999 242.72592554H220.72888889c-24.27259221 0-48.54518557-24.27259221-48.54518556-48.54518556s24.27259221-48.54518557 48.54518556-48.54518444h582.54222222c24.27259221 0 48.54518557 24.27259221 48.54518556 48.54518444s-24.27259221 48.54518557-48.54518556 48.54518556z" fill="currentColor"></path>
</svg>
        16
      </div>
      <div class="count-box--item">
        <svg class="icon icon-tags" viewBox="0 0 1098 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M283.42180005 272q0-28.38857157-20.09142843-48.48000001t-48.47999998-20.09142842-48.48000002 20.09142842-20.09142846 48.48000001 20.09142846 48.48 48.48000002 20.09142843 48.47999998-20.09142843 20.09142843-48.48zM855.0332285 580.57142843q0 28.38857157-19.81714313 48.2057147l-263.03999997 263.58857157q-20.9142853 19.81714313-48.75428534 19.81714312-28.38857157 0-48.20571468-19.81714312l-383.04-383.58857157q-20.36571468-19.81714313-34.55999999-54.10285688t-14.19428534-62.6742853l0-222.85714313q0-27.84000002 20.36571469-48.20571469t48.2057147-20.36571466l222.85714313 0q28.38857157 0 62.6742853 14.19428529t54.65142842 34.55999999l383.04000001 382.49142843q19.81714313 20.9142853 19.81714314 48.75428532zM1060.74751475 580.57142843q0 28.38857157-19.81714313 48.2057147l-263.04 263.58857157q-20.9142853 19.81714313-48.75428531 19.81714312-19.26857155 0-31.61142843-7.47428531t-28.38857159-24.13714314l251.79428534-251.7942853q19.81714313-19.81714313 19.81714308-48.20571469 0-27.84000002-19.81714308-48.75428531l-383.04000001-382.49142845q-20.36571468-20.36571468-54.65142842-34.55999999t-62.67428532-14.19428534l120 0q28.38857157 0 62.67428532 14.19428534t54.65142842 34.55999999l383.03999998 382.49142845q19.81714313 20.9142853 19.81714314 48.75428531z" fill="currentColor"></path>
</svg>
        40
      </div>
    </div>
  </div>
</section>
      
      
      
      
<section class="widget-toc widget-item layout-margin content-padding--primary soft-size--large soft-style--box">
  <div class="widget-title">
    <svg class="icon icon-toc" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M134.50666666 767.46666668H460.8c27.73333333 0 50.24000001 22.50666668 50.24000001 50.23999999v50.13333333c0 27.73333333-22.50666668 50.24000001-50.24000001 50.24000001H134.50666666c-27.73333333 0-50.24000001-22.50666668-50.23999999-50.24000001v-50.13333333c0.10666668-27.73333333 22.50666668-50.24000001 50.24000001-50.24000001zM84.37333332 541.65333333h326.18666669c27.73333333 0 50.24000001 22.39999999 50.23999999 50.13333334v50.24000001c0 27.73333333-22.50666668 50.24000001-50.24000002 50.23999999H84.37333332c-27.73333333 0-50.24000001-22.50666668-50.23999999-50.23999999v-50.24000001c0-27.73333333 22.50666668-50.13333334 50.24000001-50.13333334zM134.50666666 315.83999999H460.8c27.73333333 0 50.24000001 22.50666668 50.24000001 50.24000001v50.24000001c0 27.73333333-22.50666668 50.13333334-50.24000001 50.13333333H134.50666666c-27.73333333 0-50.24000001-22.39999999-50.23999999-50.13333333v-50.24000001c0.10666668-27.84000001 22.50666668-50.24000001 50.24000001-50.23999999zM209.81333332 89.91999999h326.18666671c27.73333333 0 50.24000001 22.39999999 50.23999997 50.13333335v50.23999999c0 27.73333333-22.50666668 50.24000001-50.24000001 50.24000001H209.81333332c-27.73333333 0-50.24000001-22.50666668-50.23999999-50.24000001v-50.24000001c0-27.73333333 22.50666668-50.13333334 50.24000001-50.13333333zM692.05333333 623.36l274.66666669 176.00000002c23.36000001 14.93333333 30.08 45.97333334 15.14666666 69.33333332L954.77333334 910.93333333c-14.93333333 23.25333334-45.97333334 30.08-69.33333335 15.14666667l-274.66666666-176c-23.36000001-14.93333333-30.08-45.97333334-15.14666667-69.33333333l27.09333334-42.24000001c14.93333333-23.36000001 46.08000001-30.08 69.33333333-15.14666666z" fill="currentColor"></path>
</svg>
    <span>TOC</span>
  </div>
  <div class="widget-body">
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8D%95%E6%9C%BA%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">单机安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9B%86%E7%BE%A4%E9%85%8D%E7%BD%AE-%E4%B8%80%E5%8F%B0%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">2.</span> <span class="toc-text">集群配置(一台服务器)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9B%86%E7%BE%A4%E9%85%8D%E7%BD%AE-%E4%B8%89%E5%8F%B0%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">3.</span> <span class="toc-text">集群配置(三台服务器)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9B%86%E7%BE%A4%E9%85%8D%E7%BD%AEkraft"><span class="toc-number">4.</span> <span class="toc-text">集群配置kraft</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95"><span class="toc-number">5.</span> <span class="toc-text">测试</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95"><span class="toc-number">5.1.</span> <span class="toc-text">性能测试</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#kafka-producer-perf-test-sh"><span class="toc-number">5.1.1.</span> <span class="toc-text">kafka-producer-perf-test.sh</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#kafka-consumer-perf-test-sh"><span class="toc-number">5.1.2.</span> <span class="toc-text">kafka-consumer-perf-test.sh</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%8D%E5%BD%B9%E6%96%B0%E8%8A%82%E7%82%B9"><span class="toc-number">6.</span> <span class="toc-text">服役新节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%80%E5%BD%B9%E6%97%A7%E7%BB%93%E7%82%B9"><span class="toc-number">7.</span> <span class="toc-text">退役旧结点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8C%87%E5%AE%9A%E5%88%86%E5%8C%BA%E5%89%AF%E6%9C%AC"><span class="toc-number">8.</span> <span class="toc-text">指定分区副本</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A2%9E%E5%8A%A0%E5%88%86%E5%8C%BA%E5%89%AF%E6%9C%AC"><span class="toc-number">9.</span> <span class="toc-text">增加分区副本</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%B8%E5%BF%83%E5%8F%82%E6%95%B0%E9%85%8D%E7%BD%AE"><span class="toc-number">10.</span> <span class="toc-text">核心参数配置</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%94%9F%E4%BA%A7%E8%80%85"><span class="toc-number">10.1.</span> <span class="toc-text">生产者</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B6%88%E8%B4%B9%E8%80%85"><span class="toc-number">10.2.</span> <span class="toc-text">消费者</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#broker"><span class="toc-number">10.3.</span> <span class="toc-text">broker</span></a></li></ol></li></ol>
  </div>
</section>

    </div>
  
    <div class="article-info">
      
      
      
      
      <section id="blog-content" class="article-entry markdown-body layout-margin content-padding--large soft-size--large soft-style--box">
        <h3 id="单机安装"><a href="#单机安装" class="headerlink" title="单机安装"></a>单机安装</h3><p><a href="https://rocpenghua.gitee.io/2022/04/26/centos7-an-zhuang-kafka/">centos7安装kafka | 小鹏驿站 (gitee.io)</a></p>
<h3 id="集群配置-一台服务器"><a href="#集群配置-一台服务器" class="headerlink" title="集群配置(一台服务器)"></a>集群配置(一台服务器)</h3><ul>
<li><code>kafka9001.properties</code>配置</li>
</ul>
<pre><code class="prettyprint">#修改配置
broker.id=1
host.name=192.168.101.143
listeners=PLAINTEXT://192.168.101.143:9001
advertised.listeners=PLAINTEXT://192.168.101.143:9001
log.dirs=/opt/module/kafka/datas-logs1
</code></pre>
<ul>
<li><code>kafka9002.properties</code>配置</li>
</ul>
<pre><code class="prettyprint">#修改配置
broker.id=2
host.name=192.168.101.143
listeners=PLAINTEXT://192.168.101.143:9002
advertised.listeners=PLAINTEXT://192.168.101.143:9002
log.dirs=/opt/module/kafka/datas-logs2
</code></pre>
<ul>
<li><code>kafka9003.properties</code>配置</li>
</ul>
<pre><code class="prettyprint">#修改配置
broker.id=3
host.name=192.168.101.143
listeners=PLAINTEXT://192.168.101.143:9003
advertised.listeners=PLAINTEXT://192.168.101.143:9003
log.dirs=/opt/module/kafka/datas-logs3
</code></pre>
<blockquote>
<p> 启动</p>
</blockquote>
<pre><code class="prettyprint">./kafka-server-start.sh ../config/kafka9001.properties &amp;
./kafka-server-start.sh ../config/kafka9002.properties &amp;
./kafka-server-start.sh ../config/kafka9003.properties &amp;
</code></pre>
<blockquote>
<p>启动脚本</p>
</blockquote>
<pre><code class="prettyprint">#!/bin/bash

case $1 in
&quot;start&quot;)&#123;
    for i in 9001 9002 9003
    do
        echo  ------------- kafka $i 启动 ------------
        &quot;source /etc/profile;nohup /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/kafka$i.properties&quot;
    done
&#125;
;;
&quot;stop&quot;)&#123;
    echo  ------------- kafka  停止 ------------
    &quot;/opt/module/kafka/bin/kafka-server-stop.sh &quot;
&#125;
;;
esac
</code></pre>
<h3 id="集群配置-三台服务器"><a href="#集群配置-三台服务器" class="headerlink" title="集群配置(三台服务器)"></a>集群配置(三台服务器)</h3><ul>
<li><p>准备三台服务器<code>node2</code>,<code>node3</code>,<code>node4</code></p>
</li>
<li><p>修改<code>node2</code>配置文件<code>config/server.properties</code></p>
</li>
</ul>
<pre><code class="prettyprint"># broker 的全局唯一编号，不能重复，只能是数字。
broker.id=0
# kafka 运行日志(数据)存放的路径，路径不需要提前创建，kafka 自动帮你创建，可以配置多个磁盘路径，路径与路径之间可以用&quot;，&quot;分隔
log.dirs=/opt/module/kafka/datas
# 配置连接 Zookeeper 集群地址（在 zk 根目录下创建/kafka，方便管理）
zookeeper.connect=node2:2181,node3:2181,node4:2181/kafka
</code></pre>
<ul>
<li>分发安装包</li>
</ul>
<blockquote>
<p>xsync配置<a href="https://rocpenghua.gitee.io/2022/07/12/linux-jiao-ben/">linux脚本 | 小鹏驿站 (gitee.io)</a></p>
</blockquote>
<pre><code class="prettyprint">cd /opt/module
xsync kafka/
</code></pre>
<ul>
<li>修改<code>node3</code>,<code>node4</code>下面<code>config/server.properties</code></li>
</ul>
<pre><code class="prettyprint"># node3 broker 的全局唯一编号，不能重复，只能是数字。
broker.id=1
# node4 broker 的全局唯一编号，不能重复，只能是数字。
broker.id=2
</code></pre>
<ul>
<li>环境变量增加<code>kafka</code>配置（node2,node3,node4）</li>
</ul>
<pre><code class="prettyprint">vim /etc/profile
</code></pre>
<p>添加内容</p>
<pre><code class="prettyprint">#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka
export PATH=$PATH:$KAFKA_HOME/bin
</code></pre>
<p>刷新环境变量脚本</p>
<pre><code class="prettyprint">source /etc/profile
</code></pre>
<ul>
<li>zk启动脚本，kafka启动脚本编写</li>
</ul>
<p><a href="https://rocpenghua.gitee.io/2022/07/12/linux-jiao-ben/">linux脚本 | 小鹏驿站 (gitee.io)</a></p>
<pre><code class="prettyprint"># 先启动zk
./zk.sh start
# 再启动kafka
./kf.sh start
</code></pre>
<h3 id="集群配置kraft"><a href="#集群配置kraft" class="headerlink" title="集群配置kraft"></a>集群配置<code>kraft</code></h3><ul>
<li><p>准备三台服务器<code>node2</code>,<code>node3</code>,<code>node4</code></p>
</li>
<li><p>修改<code>node2</code>配置文件<code>config/kraft/server.properties</code></p>
</li>
</ul>
<pre><code class="prettyprint"># 节点 id
node.id=2
#全 Controller 列表
controller.quorum.voters=2@node2:9093,3@node3:9093,4@node4:9093
#broker 对外暴露的地址
advertised.Listeners=PLAINTEXT://node2:9092
#kafka 数据存储目录
log.dirs=/opt/module/kafka/data
</code></pre>
<ul>
<li>分发安装包</li>
</ul>
<blockquote>
<p>xsync配置<a href="https://rocpenghua.gitee.io/2022/07/12/linux-jiao-ben/">linux脚本 | 小鹏驿站 (gitee.io)</a></p>
</blockquote>
<pre><code class="prettyprint">cd /opt/module
xsync kafka/
</code></pre>
<ul>
<li>修改<code>node3</code>,<code>node4</code>下面<code>config/server.properties</code></li>
</ul>
<pre><code class="prettyprint"># 节点 id
node.id=3
# broker 对外暴露的地址
advertised.Listeners=PLAINTEXT://node3:9092


# 节点 id
node.id=4
# broker 对外暴露的地址
advertised.Listeners=PLAINTEXT://node4:9092
</code></pre>
<ul>
<li>环境变量增加<code>kafka</code>配置（node2,node3,node4）</li>
</ul>
<pre><code class="prettyprint">vim /etc/profile
</code></pre>
<p>添加内容</p>
<pre><code class="prettyprint">#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka
export PATH=$PATH:$KAFKA_HOME/bin
</code></pre>
<p>刷新环境变量脚本</p>
<pre><code class="prettyprint">source /etc/profile
</code></pre>
<ul>
<li>初始化集群数据目录</li>
</ul>
<pre><code class="prettyprint"># 生成存储目录唯一ID
[root@node2 ~]# cd /opt/module/kafka/bin
[root@node2 bin]# ./kafka-storage.sh random-uuid
MBJ8mVoITCC3hDl886zuyA
# node2
[root@node2 bin]# ./kafka-storage.sh format -t MBJ8mVoITCC3hDl886zuyA -c /opt/module/kafka/config/kraft/server.properties 
Formatting /opt/module/kafka/data

# node3
[root@node3 bin]# ./kafka-storage.sh format -t MBJ8mVoITCC3hDl886zuyA -c /opt/module/kafka/config/kraft/server.properties 
Formatting /opt/module/kafka/data

# node4
[root@node4 bin]# ./kafka-storage.sh format -t MBJ8mVoITCC3hDl886zuyA -c /opt/module/kafka/config/kraft/server.properties 
Formatting /opt/module/kafka/data
</code></pre>
<ul>
<li>启动</li>
</ul>
<pre><code class="prettyprint">[root@node2 bin]# ./kafka-server-start.sh -daemon ../config/kraft/server.properties

[root@node3 bin]# ./kafka-server-start.sh -daemon ../config/kraft/server.properties

[root@node4 bin]# ./kafka-server-start.sh -daemon ../config/kraft/server.properties
</code></pre>
<ul>
<li>启动脚本</li>
</ul>
<pre><code class="prettyprint">#!/bin/bash

case $1 in
&quot;start&quot;)&#123;
    for i in node2 node3 node4
    do
        echo  ------------- kafka $i 启动 ------------
        ssh $i &quot;source /etc/profile;nohup /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/kraft/server.properties&quot;
    done
&#125;
;;
&quot;stop&quot;)&#123;
    for i in node2 node3 node4
    do
        echo  ------------- kafka $i 停止 ------------
        ssh $i &quot;/opt/module/kafka/bin/kafka-server-stop.sh &quot;
    done
&#125;
;;
esac
</code></pre>
<h3 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h3><pre><code class="prettyprint">#创建
./kafka-topics.sh --create --topic &quot;first32&quot; --bootstrap-server 192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003 --partitions 3 --replication-factor 2
#查看描述
./kafka-topics.sh --describe --topic &quot;first32&quot; --bootstrap-server 192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003
</code></pre>
<ul>
<li>3个partitions 2个副本</li>
</ul>


<ul>
<li>3个partitions 3个副本</li>
</ul>


<ul>
<li><code>kafka-console-consumer.sh</code></li>
</ul>
<pre><code class="prettyprint"># from-beginning 从头开始
./kafka-console-consumer.sh --bootstrap-server 192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003 --from-beginning --topic first33
</code></pre>
<ul>
<li><code>kafka-console-producer.sh</code></li>
</ul>
<pre><code class="prettyprint">./kafka-console-producer.sh --bootstrap-server 192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003 --topic first33
</code></pre>
<h4 id="性能测试"><a href="#性能测试" class="headerlink" title="性能测试"></a>性能测试</h4><h5 id="kafka-producer-perf-test-sh"><a href="#kafka-producer-perf-test-sh" class="headerlink" title="kafka-producer-perf-test.sh"></a><code>kafka-producer-perf-test.sh</code></h5><pre><code class="prettyprint">#生产数量100万个 每个数据1000字节 每秒两千个
[root@rocketmq-nameserver1 bin]# ./kafka-producer-perf-test.sh --topic test --record-size 1024 --num-records 1000000 --throughput 10000 --producer-props bootstrap.servers=192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003 batch.size=16384 linger.ms=0
</code></pre>
<blockquote>
<p>参数说明</p>
<ul>
<li>record-size 是一条信息有多大，单位是字节，本次测试设置为 1k</li>
<li>num-records 是总共发送多少条信息，本次测试设置为 100 万条</li>
<li>throughput 是每秒多少条信息，设成-1，表示不限流，尽可能快的生产数据，可测出生产者最大吞吐量。本次实验设置为每秒钟 1 万条</li>
<li>producer-props 后面可以配置生产者相关参数，batch.size 配置为 16k</li>
</ul>
</blockquote>
<table>
<thead>
<tr>
<th>参数</th>
<th>压测结果（机器不同效率也有影响）</th>
</tr>
</thead>
<tbody><tr>
<td>batch.size&#x3D;16384 linger.ms&#x3D;0</td>
<td>1000000 records sent, 6565.384666 records&#x2F;sec (6.41 MB&#x2F;sec), 4552.62 ms avg latency, 11020.00 ms max latency, 4028 ms 50th, 8530 ms 95th, 10529 ms 99th, 10988 ms 99.9th.</td>
</tr>
<tr>
<td>batch.size&#x3D;32768 linger.ms&#x3D;0</td>
<td>1000000 records sent, 9996.101520 records&#x2F;sec (9.76 MB&#x2F;sec), 1187.20 ms avg latency, 4831.00 ms max latency, 374 ms 50th, 4008 ms 95th, 4556 ms 99th, 4731 ms 99.9th.</td>
</tr>
<tr>
<td>batch.size&#x3D;4096 linger.ms&#x3D;0</td>
<td>1000000 records sent, 3801.052892 records&#x2F;sec (3.71 MB&#x2F;sec), 6347.24 ms avg latency, 16980.00 ms max latency, 7125 ms 50th, 13355 ms 95th, 16519 ms 99th, 16904 ms 99.9th.</td>
</tr>
<tr>
<td>batch.size&#x3D;4096 linger.ms&#x3D;50</td>
<td>1000000 records sent, 4139.569733 records&#x2F;sec (4.04 MB&#x2F;sec), 5786.82 ms avg latency, 17962.00 ms max latency, 3667 ms 50th, 16259 ms 95th, 17789 ms 99th, 17923 ms 99.9th</td>
</tr>
<tr>
<td>batch.size&#x3D;32768 linger.ms&#x3D;0 compression.type&#x3D;snappy</td>
<td>1000000 records sent, 9997.600576 records&#x2F;sec (9.76 MB&#x2F;sec), 1865.76 ms avg latency, 5883.00 ms max latency, 1455 ms 50th, 4909 ms 95th, 5438 ms 99th, 5801 ms 99.9th.</td>
</tr>
<tr>
<td>batch.size&#x3D;32768 linger.ms&#x3D;50 compression.type&#x3D;gzip</td>
<td>1000000 records sent, 9998.300289 records&#x2F;sec (9.76 MB&#x2F;sec), 37.91 ms avg latency, 739.00 ms max latency, 6 ms 50th, 199 ms 95th, 562 ms 99th, 639 ms 99.9th.</td>
</tr>
<tr>
<td>batch.size&#x3D;16384 linger.ms&#x3D;50 compression.type&#x3D;gzip buffer.memory&#x3D;67108864</td>
<td>1000000 records sent, 9998.400256 records&#x2F;sec (9.76 MB&#x2F;sec), 45.36 ms avg latency, 1219.00 ms max latency, 4 ms 50th, 260 ms 95th, 945 ms 99th, 1161 ms 99.9th</td>
</tr>
</tbody></table>
<h5 id="kafka-consumer-perf-test-sh"><a href="#kafka-consumer-perf-test-sh" class="headerlink" title="kafka-consumer-perf-test.sh"></a><code>kafka-consumer-perf-test.sh</code></h5><pre><code class="prettyprint">#消费数量10万个
./kafka-consumer-perf-test.sh --bootstrap-server 192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003 --topic test --messages 1000000 --consumer.config ../config/consumer.properties
</code></pre>
<blockquote>
<ul>
<li>–bootstrap-server 指定 Kafka 集群地址</li>
<li>–topic 指定 topic 的名称</li>
<li>–messages 总共要消费的消息个数。本次实验 100 万条。</li>
</ul>
<p>修改配置consumer.properties</p>
<p>max.poll.records&#x3D;500：一次 poll 拉取数据返回消息的最大条数</p>
</blockquote>
<table>
<thead>
<tr>
<th>参数</th>
<th>结果start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec</th>
</tr>
</thead>
<tbody><tr>
<td>max.poll.records&#x3D;500 fetch.max.bytes&#x3D;52428800</td>
<td>2022-07-21 20:39:56:913, 2022-07-21 20:40:07:561, 976.7051, <strong>91.7266</strong>, 1000146, 93928.0616, 1531, 9117, 107.1301, 109701.2175</td>
</tr>
<tr>
<td>max.poll.records&#x3D;2000 fetch.max.bytes&#x3D;52428800</td>
<td>2022-07-21 20:41:14:571, 2022-07-21 20:41:19:923, 976.9424, <strong>182.5378</strong>, 1000389, 186918.7220, 641, 4711, 207.3747, 212351.7300</td>
</tr>
<tr>
<td>max.poll.records&#x3D;2000 fetch.max.bytes&#x3D;104857600</td>
<td>2022-07-21 20:42:24:476, 2022-07-21 20:42:29:266, 977.1650, <strong>204.0011</strong>, 1000617, 208897.0772, 509, 4281, 228.2563, 233734.4078</td>
</tr>
</tbody></table>
<h3 id="服役新节点"><a href="#服役新节点" class="headerlink" title="服役新节点"></a>服役新节点</h3><ul>
<li>新增配置文件<code>kafka9004.properties</code></li>
</ul>
<pre><code class="prettyprint">cp kafka9001.properties kafka9004.properties
</code></pre>
<ul>
<li>修改内容</li>
</ul>
<pre><code class="prettyprint">#修改配置
broker.id=4
host.name=192.168.101.143
listeners=PLAINTEXT://192.168.101.143:9004
advertised.listeners=PLAINTEXT://192.168.101.143:9004
log.dirs=/opt/module/kafka/datas-logs4
</code></pre>
<ul>
<li>启动新节点</li>
</ul>
<pre><code class="prettyprint">./kafka-server-start.sh ../config/kafka9004.properties &amp;
</code></pre>
<ul>
<li>创建一个需要负载均衡的主题<code>topics-to-move.json</code></li>
</ul>
<pre><code class="prettyprint"># 可以传多个主题
&#123;
    &quot;topics&quot;: [
        &#123;&quot;topic&quot;: &quot;first&quot;&#125;
    ],
    &quot;version&quot;: 1
&#125;
</code></pre>
<ul>
<li>生成负载均衡计划</li>
</ul>
<pre><code class="prettyprint">bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --topics-to-move-json-file topics-to-move.json --broker-list &quot;1,2,3,4&quot; --generate
</code></pre>
<blockquote>
<p>执行结果</p>
</blockquote>
<pre><code class="prettyprint">Current partition replica assignment
&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[2,1],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[3,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;

Proposed partition reassignment configuration
# 需要执行的存储计划json
&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[2,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[3,4],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;
</code></pre>
<ul>
<li>创建副本存储计划<code>increase-replication.json</code></li>
</ul>
<pre><code class="prettyprint">&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[2,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[3,4],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;
</code></pre>
<ul>
<li>执行副本存储计划</li>
</ul>
<pre><code class="prettyprint">bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file increase-replication.json --execute
</code></pre>
<blockquote>
<p>执行结果</p>
</blockquote>
<pre><code class="prettyprint">Current partition replica assignment

&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[2,1],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[3,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for first-0,first-1,first-2
</code></pre>
<ul>
<li>验证副本存储计划</li>
</ul>
<pre><code class="prettyprint">bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file increase-replication.json --verify
</code></pre>
<blockquote>
<p>执行结果</p>
</blockquote>
<pre><code class="prettyprint">Status of partition reassignment:
Reassignment of partition first-0 is complete.
Reassignment of partition first-1 is complete.
Reassignment of partition first-2 is complete.

Clearing broker-level throttles on brokers 1,2,3,4
Clearing topic-level throttles on topic first
</code></pre>
<h3 id="退役旧结点"><a href="#退役旧结点" class="headerlink" title="退役旧结点"></a>退役旧结点</h3><ul>
<li>创建一个需要负载均衡的主题<code>topics-to-move.json</code></li>
</ul>
<pre><code class="prettyprint">&#123;
    &quot;topics&quot;: [
        &#123;&quot;topic&quot;: &quot;first&quot;&#125;
    ],
    &quot;version&quot;: 1
&#125;
</code></pre>
<ul>
<li>创建执行计划</li>
</ul>
<pre><code class="prettyprint">bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --topics-to-move-json-file topics-to-move.json --broker-list &quot;1,2,3&quot; --generate
</code></pre>
<blockquote>
<p>执行结果</p>
</blockquote>
<pre><code class="prettyprint">Current partition replica assignment
&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[2,1],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[3,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;

Proposed partition reassignment configuration
&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[3,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[1,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[2,1],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;
</code></pre>
<ul>
<li>创建副本存储计划<code>decrease-replication.json</code></li>
</ul>
<pre><code class="prettyprint">&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[3,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[1,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[2,1],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;
</code></pre>
<ul>
<li>执行副本存储计划</li>
</ul>
<pre><code class="prettyprint">bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file decrease-replication.json --execute
</code></pre>
<blockquote>
<p>执行结果</p>
</blockquote>
<pre><code class="prettyprint">Current partition replica assignment

&#123;&quot;version&quot;:1,&quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,2],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[2,3],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;,&#123;&quot;topic&quot;:&quot;first&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[3,4],&quot;log_dirs&quot;:[&quot;any&quot;,&quot;any&quot;]&#125;]&#125;

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for first-0,first-1,first-2
</code></pre>
<ul>
<li>验证副本存储计划</li>
</ul>
<pre><code class="prettyprint">bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file decrease-replication.json --verify
</code></pre>
<blockquote>
<p>执行结果</p>
</blockquote>
<pre><code class="prettyprint">Status of partition reassignment:
Reassignment of partition first-0 is complete.
Reassignment of partition first-1 is complete.
Reassignment of partition first-2 is complete.

Clearing broker-level throttles on brokers 1,2,3,4
Clearing topic-level throttles on topic first
</code></pre>
<h3 id="指定分区副本"><a href="#指定分区副本" class="headerlink" title="指定分区副本"></a>指定分区副本</h3><ul>
<li>创建分区主题</li>
</ul>
<pre><code class="prettyprint"># 4分区 2 副本
./kafka-topics.sh --create --topic &quot;rocpenghua3&quot; --bootstrap-server 192.168.101.143:9001 --partitions 4 --replication-factor 2
</code></pre>
<ul>
<li>创建分区配置<code>assign-replication-factor.json</code></li>
</ul>
<pre><code class="prettyprint">&#123;
    &quot;version&quot;:1,
    &quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;rocpenghua3&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,2]&#125;,
        &#123;&quot;topic&quot;:&quot;rocpenghua3&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[1,2]&#125;,
        &#123;&quot;topic&quot;:&quot;rocpenghua3&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[2,1]&#125;,
        &#123;&quot;topic&quot;:&quot;rocpenghua3&quot;,&quot;partition&quot;:3,&quot;replicas&quot;:[2,1]&#125;]
&#125;
</code></pre>
<ul>
<li>执行副本存储计划</li>
</ul>
<pre><code class="prettyprint">./kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file ../assign-replication-factor.json --execute
</code></pre>
<ul>
<li>验证副本存储计划</li>
</ul>
<pre><code class="prettyprint">./kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file ../assign-replication-factor.json --verify
</code></pre>
<ul>
<li>查看主题信息</li>
</ul>
<pre><code class="prettyprint">bin/kafka-topics.sh --bootstrap-server 192.168.101.143:9001 --describe --topic &quot;rocpenghua3&quot;
</code></pre>
<blockquote>
<p>结果信息</p>
</blockquote>
<pre><code class="prettyprint">Topic: rocpenghua3	TopicId: e7ZcYefrQ_ekcjzbEX4fbw	PartitionCount: 4	ReplicationFactor: 2	Configs: segment.bytes=1073741824
    Topic: rocpenghua3	Partition: 0	Leader: 2	Replicas: 1,2	Isr: 2,1
    Topic: rocpenghua3	Partition: 1	Leader: 1	Replicas: 1,2	Isr: 2,1
    Topic: rocpenghua3	Partition: 2	Leader: 2	Replicas: 2,1	Isr: 1,2
    Topic: rocpenghua3	Partition: 3	Leader: 1	Replicas: 2,1	Isr: 1,2
</code></pre>
<h3 id="增加分区副本"><a href="#增加分区副本" class="headerlink" title="增加分区副本"></a>增加分区副本</h3><ul>
<li>创建主题</li>
</ul>
<pre><code class="prettyprint"># 3分区 1 副本
./kafka-topics.sh --create --topic &quot;rocpenghua4&quot; --bootstrap-server 192.168.101.143:9001 --partitions 3 --replication-factor 1
</code></pre>
<ul>
<li>创建分区配置<code>increase-replication-factor.json</code></li>
</ul>
<pre><code class="prettyprint">&#123;
    &quot;version&quot;:1,
    &quot;partitions&quot;:[&#123;&quot;topic&quot;:&quot;rocpenghua4&quot;,&quot;partition&quot;:0,&quot;replicas&quot;:[1,2,3]&#125;,
    &#123;&quot;topic&quot;:&quot;rocpenghua4&quot;,&quot;partition&quot;:1,&quot;replicas&quot;:[1,2,3]&#125;,
    &#123;&quot;topic&quot;:&quot;rocpenghua4&quot;,&quot;partition&quot;:2,&quot;replicas&quot;:[1,2,3]&#125;]
&#125;
</code></pre>
<ul>
<li>执行副本存储计划</li>
</ul>
<pre><code class="prettyprint">./kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file ../increase-replication-factor.json --execute
</code></pre>
<ul>
<li>验证副本存储计划</li>
</ul>
<pre><code class="prettyprint">./kafka-reassign-partitions.sh --bootstrap-server 192.168.101.143:9001 --reassignment-json-file ../increase-replication-factor.json --verify
</code></pre>
<ul>
<li>查看主题信息</li>
</ul>
<pre><code class="prettyprint">bin/kafka-topics.sh --bootstrap-server 192.168.101.143:9001 --describe --topic &quot;rocpenghua4&quot;
</code></pre>
<h3 id="核心参数配置"><a href="#核心参数配置" class="headerlink" title="核心参数配置"></a>核心参数配置</h3><h4 id="生产者"><a href="#生产者" class="headerlink" title="生产者"></a>生产者</h4><ul>
<li><p><code>bootstrap.servers</code>：生 产 者 连 接 集 群 所 需 的 broker 地 址 清 单 。 例 如<br>192.168.101.143:9001,192.168.101.143:9002，可以设置 1 个或者多个，中间用逗号隔开，并非所有的broker</p>
</li>
<li><p><code>key.serializer</code> 和<code>value.serializer</code>：指定发送消息的 key 和 value 的序列化类型。一定要写<br>全类名</p>
</li>
<li><p><code>buffer.memory</code>：RecordAccumulator 缓冲区总大小，<strong>默认 32m</strong>。</p>
</li>
<li><p><code>batch.size</code>：缓冲区一批数据最大值，<strong>默认 16k</strong>。适当增加该值，可以提高吞吐量，但是如果该值设置太大，会导致数据传输延迟增加。</p>
</li>
<li><p><code>linger.ms</code>：如果数据迟迟未达到 batch.size，sender 等待 linger.time之后就会发送数据。单位 ms，<strong>默认值是 0ms</strong>，表示没有延迟。生产环境建议该值大小为 5-100ms 之间</p>
</li>
<li><p><code>acks</code>：<strong>默认值是-1</strong></p>
<ul>
<li>0：生产者发送过来的数据，不需要等数据落盘应答。</li>
<li>1：生产者发送过来的数据，Leader 收到数据后应答。</li>
<li>-1（all）：生产者发送过来的数据，Leader+和 isr 队列里面的所有节点收齐数据后应答。</li>
</ul>
</li>
<li><p><code>max.in.flight.requests.per.connection</code>：允许最多没有返回 ack 的次数，<strong>默认为 5</strong>，开启幂等性要保证该值是 1-5 的数字</p>
</li>
<li><p><code>retries</code>：当消息发送出现错误的时候，系统会重发消息。retries表示重试次数。<strong>默认是 int 最大值</strong>,2147483647。如果设置了重试，还想保证消息的有序性，需要设置MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION&#x3D;1否则在重试此失败消息的时候，其他的消息可能发送成功了</p>
</li>
<li><p><code>retry.backoff.ms</code>：两次重试之间的时间间隔，<strong>默认是 100ms</strong>。</p>
</li>
<li><p><code>enable.idempotence</code>：是否开启幂等性，<strong>默认 true</strong>，开启幂等性</p>
</li>
<li><p><code>compression.type</code>：生产者发送的所有数据的压缩方式。<strong>默认是 none</strong>，也就是不压缩。支持压缩类型：none、gzip、snappy、lz4 和 zstd</p>
</li>
<li><p><code>partitioner.class</code>：分区器</p>
<ul>
<li><p>默认：<code>org.apache.kafka.clients.producer.internals.DefaultPartitioner</code></p>
</li>
<li><p>自定义：<code>properties.put(ProducerConfig.PARTITIONER_CLASS_CONFIG,&quot;com.rocpenghua.kafka.producer.MyPartitioner&quot;);</code></p>
<pre><code class="prettyprint">public class MyPartitioner implements Partitioner &#123;
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) &#123;
        // 获取数据 
        String msgValues = value.toString();
        int partition;

        if (msgValues.contains(&quot;rocpenghua&quot;))&#123;
            partition = 2;
        &#125;else &#123;
            partition = 1;
        &#125;
        return partition;
    &#125;
    @Override
    public void close() &#123;

    &#125;
    @Override
    public void configure(Map&lt;String, ?&gt; configs) &#123;

    &#125;
&#125;
</code></pre>
</li>
</ul>
</li>
<li><p>事务开启</p>
<ul>
<li><pre><code class="prettyprint">public class CustomProducerTranactions &#123;
    public static void main(String[] args) &#123;
        // 0 配置
        Properties properties = new Properties();
        // 连接集群 bootstrap.servers
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, &quot;192.168.101.143:9001,192.168.101.143:9002,192.168.101.143:9003&quot;);
        // 指定对应的key和value的序列化类型 key.serializer
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        // 指定事务id
        properties.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, &quot;tranactional_id_01&quot;);
        // 1 创建kafka生产者对象
        KafkaProducer&lt;String, String&gt; kafkaProducer = new KafkaProducer&lt;&gt;(properties);
        //初始化事务
        kafkaProducer.initTransactions();
        //开启事务
        kafkaProducer.beginTransaction();
        try &#123;
            // 2 发送数据
            for (int i = 0; i &lt; 5; i++) &#123;
                kafkaProducer.send(new ProducerRecord&lt;&gt;(&quot;first&quot;, &quot;rocpenghua&quot; + i));
            &#125;
            int i = 1 / 0;
            //提交事务
            kafkaProducer.commitTransaction();
        &#125; catch (Exception e) &#123;
            //放弃事务
            kafkaProducer.abortTransaction();
        &#125; finally &#123;
            // 3 关闭资源
            kafkaProducer.close();
        &#125;
    &#125;
&#125;
</code></pre>
</li>
</ul>
<blockquote>
<p>提高吞吐量配置</p>
<ul>
<li>buffer.memory：缓冲区大小 默认 32m</li>
<li>batch.size：缓冲区一批数据最大值 默认 16k</li>
<li>linger.ms：默认值是 0ms，表示没有延迟</li>
<li>compression.type：默认是 none</li>
</ul>
<p>数据可靠性</p>
<ul>
<li>acks：默认值是-1</li>
</ul>
<p>数据去重</p>
<ul>
<li>enable.idempotence：开启幂等性，默认 true</li>
</ul>
<p>数据乱序</p>
<ul>
<li>enable.idempotence：开启幂等性，默认 true</li>
<li>max.in.flight.requests.per.connection：允许最多没有返回 ack 的次数，默认为 5，开启幂等性要保证该值是 1-5 的数字</li>
</ul>
</blockquote>
</li>
</ul>
<h4 id="消费者"><a href="#消费者" class="headerlink" title="消费者"></a>消费者</h4><ul>
<li><p><code>bootstrap.servers</code>：向 Kafka 集群建立初始连接用到的 host&#x2F;port 列表。</p>
</li>
<li><p><code>key.deserializer</code> 和 <code>value.deserializer</code>：指定接收消息的 key 和 value 的反序列化类型</p>
</li>
<li><p><code>group.id</code>：标记消费者所属的消费者组。命令默认生成。</p>
</li>
<li><p><code>enable.auto.commit</code>：<strong>默认值为 true</strong>，消费者会自动周期性地向服务器提交偏移量</p>
</li>
<li><p><code>auto.commit.interval.ms</code>：如果设置了 enable.auto.commit 的值为 true， 则该值定义了消费者偏移量向 Kafka 提交的频率，<strong>默认 5s</strong>。</p>
</li>
<li><p><code>auto.offset.reset</code>：当 Kafka 中没有初始偏移量或当前偏移量在服务器中不存在（如，数据被删除了），该如何处理？ </p>
<ul>
<li>earliest：自动重置偏移量到最早的偏移量。</li>
<li>latest：<strong>默认，自动重置偏移量为最新的偏移量</strong>。 </li>
<li>none：如果消费组原来的（previous）偏移量不存在，则向消费者抛异常。 </li>
<li>anything：向消费者抛异常</li>
</ul>
</li>
<li><p><code>offsets.topic.num.partitions</code>：__consumer_offsets 的分区数，<strong>默认是 50 个分区</strong>。</p>
</li>
<li><p><code>heartbeat.interval.ms</code>：Kafka 消费者和 coordinator 之间的心跳时间，<strong>默认 3s</strong>。该条目的值必须小于 session.timeout.ms ，也不应该高于session.timeout.ms 的 1&#x2F;3。</p>
</li>
<li><p><code>session.timeout.ms</code>：Kafka 消费者和 coordinator 之间连接超时时间，<strong>默认 45s</strong>。超过该值，该消费者被移除，消费者组执行再平衡。</p>
</li>
<li><p><code>max.poll.interval.ms</code>：消费者处理消息的最大时长，<strong>默认是 5 分钟</strong>。超过该值，该消费者被移除，消费者组执行再平衡。</p>
</li>
<li><p><code>fetch.min.bytes</code>：<strong>默认 1 个字节</strong>。消费者获取服务器端一批消息最小的字节数。</p>
</li>
<li><p><code>fetch.max.wait.ms</code>：<strong>默认 500ms</strong>。如果没有从服务器端获取到一批数据的最小字节数。该时间到，仍然会返回数据。</p>
</li>
<li><p><code>fetch.max.bytes</code>：<strong>默认 Default: 52428800（50 m）</strong>。消费者获取服务器端一批消息最大的字节数。如果服务器端一批次的数据大于该值（50m）仍然可以拉取回来这批数据，因此，这不是一个绝对最大值。一批次的大小受 message.max.bytes （broker config）or max.message.bytes （topic config）影响。</p>
</li>
<li><p><code>max.poll.records</code>：一次 poll 拉取数据返回消息的最大条数，<strong>默认是 500 条</strong>。</p>
</li>
<li><p><code>partition.assignment.strategy</code>：分区策略,默认<code>org.apache.kafka.clients.consumer.RangeAssignor</code> <code>org.apache.kafka.clients.consumer.CooperativeStickyAssignor</code></p>
<ul>
<li><p><code>org.apache.kafka.clients.consumer.RangeAssignor</code>‎：基于每个主题分配分区。‎</p>
</li>
<li><p><code>org.apache.kafka.clients.consumer.RoundRobinAssignor</code>‎：以轮循机制方式将分区分配给使用者。‎</p>
</li>
<li><p><code>org.apache.kafka.clients.consumer.StickyAssignor</code>‎：保证分配的最大平衡，同时保留尽可能多的现有分区分配。‎</p>
</li>
<li><p><code>org.apache.kafka.clients.consumer.CooperativeStickyAssignor</code>‎：遵循相同的粘性Assignor逻辑，但允许合作再平衡。‎</p>
</li>
</ul>
</li>
</ul>
<blockquote>
<p>消费者再平衡</p>
<ul>
<li>heartbeat.interval.ms：默认 3s，小于 session.timeout.ms，也不应该高于session.timeout.ms 的 1&#x2F;3</li>
<li>session.timeout.ms：默认 45s</li>
<li>max.poll.interval.ms：默认是 5 分钟</li>
<li>partition.assignment.strategy：默 认 策 略 是Range +CooperativeSticky</li>
</ul>
<p>消费者提高吞吐量</p>
<ul>
<li>fetch.max.bytes：Default: 52428800（50 m）</li>
<li>max.poll.records：一次 poll 拉取数据返回消息的最大条数，默认是 500 条</li>
</ul>
</blockquote>
<h4 id="broker"><a href="#broker" class="headerlink" title="broker"></a>broker</h4><ul>
<li><p><code>replica.lag.time.max.ms</code>：ISR 中，如果 Follower 长时间未向 Leader 发送通信请求或同步数据，则该 Follower 将被踢出 ISR。该时间阈值，<strong>默认 30s</strong>。</p>
</li>
<li><p><code>auto.leader.rebalance.enable</code>：<strong>默认是 true</strong>。 自动 Leader Partition 平衡。</p>
</li>
<li><p><code>leader.imbalance.per.broker.percentage</code>：**默认是 10%**。每个 broker 允许的不平衡的 leader的比率。如果每个 broker 超过了这个值，控制器会触发 leader 的平衡。</p>
</li>
<li><p><code>leader.imbalance.check.interval.seconds </code>：<strong>默认值 300 秒</strong>。检查 leader 负载是否平衡的间隔时间</p>
</li>
<li><p><code>log.segment.bytes</code>：Kafka 中 log 日志是分成一块块存储的，此配置是指 log 日志划分 成块的大小，<strong>默认值 1G</strong>。</p>
</li>
<li><p><code>log.index.interval.bytes</code>：<strong>默认 4kb</strong>，kafka 里面每当写入了 4kb 大小的日志（.log），然后就往 index 文件里面记录一个索引。</p>
</li>
<li><p><code>log.retention.hours</code>：Kafka 中数据保存的时间，<strong>默认 7 天</strong>。</p>
</li>
<li><p><code>log.retention.minutes</code>：Kafka 中数据保存的时间，分钟级别，<strong>默认关闭</strong>。</p>
</li>
<li><p><code>log.retention.ms</code>：Kafka 中数据保存的时间，毫秒级别，<strong>默认关闭</strong>。</p>
</li>
<li><p><code>log.retention.check.interval.ms</code>：检查数据是否保存超时的间隔，<strong>默认是 5 分钟</strong></p>
</li>
<li><p><code>log.retention.bytes</code>：<strong>默认等于-1</strong>，表示无穷大。超过设置的所有日志总大小，删除最早的 segment。</p>
</li>
<li><p><code>log.cleanup.policy</code>：<strong>默认是 delete</strong>，表示所有数据启用删除策略；如果设置值为 compact，表示所有数据启用压缩策略。</p>
</li>
<li><p><code>num.io.threads</code>：<strong>默认是 8</strong>。负责写磁盘的线程数。整个参数值要占总核数的 50%。</p>
</li>
<li><p><code>num.replica.fetchers</code>：副本拉取线程数，这个参数占总核数的 50%的 1&#x2F;3</p>
</li>
<li><p><code>num.network.threads</code>：<strong>默认是 3</strong>。数据传输线程数，这个参数占总核数的50%的 2&#x2F;3 。</p>
</li>
<li><p><code>log.flush.interval.messages</code>：强制页缓存刷写到磁盘的条数，<strong>默认是 long 的最大值</strong>，9223372036854775807。<strong>一般不建议修改</strong>，交给系统自己管理</p>
</li>
<li><p><code>log.flush.interval.ms</code>：每隔多久，刷数据到磁盘，默认是 null。<strong>一般不建议修改</strong>，交给系统自己管理。</p>
</li>
</ul>
<blockquote>
<p>Partition负载平衡</p>
<ul>
<li>auto.leader.rebalance.enable：建议设置为 false 关闭。</li>
<li>leader.imbalance.per.broker.percentage：默认是 10%。每个 broker 允许的不平衡的 leader的比率</li>
<li>leader.imbalance.check.interval.seconds：默认值 300 秒。检查 leader 负载是否平衡的间隔时间</li>
</ul>
<p>自动创建主题</p>
<ul>
<li>auto.create.topics.enable：默认true,生产环境改成false</li>
</ul>
<p>单条日志大于1m</p>
<ul>
<li>message.max.bytes：默认 1m，broker 端接收每个批次消息最大值</li>
<li>max.request.size：默认 1m，生产者发往 broker 每个请求消息最大值</li>
<li>replica.fetch.max.bytes：默认 1m，副本同步数据，每个批次消息最大值</li>
<li>fetch.max.bytes：默认 Default: 52428800（50 m）</li>
</ul>
</blockquote>

      </section>

      
      
        <nav class="article-nav">
          
            <div class="article-nav-item layout-padding">
  <article class="card-container article-nav-card content-padding--primary soft-size--large soft-style--box">
    
      <div class="card-cover" background-image-lazy data-img="https://api.lixingyong.com/api/images?postid=e5f2d128&type=url&itype=image"></div>
    
    <div class="card-text">
      
        <a href="/2022/08/09/redis-guo-qi-key-jian-ting/" itemprop="url">
          <h2 class="card-text--title text-ellipsis">redis过期key监听</h2>
        </a>
      
      <div class="card-text--row">Newer</div>
    </div>
  </article>
</div>
          
          
            <div class="article-nav-item layout-padding">
  <article class="card-container article-nav-card content-padding--primary soft-size--large soft-style--box">
    
      <div class="card-cover" background-image-lazy data-img="https://api.lixingyong.com/api/images?postid=705ac99d&type=url&itype=image"></div>
    
    <div class="card-text">
      
        <a href="/2022/07/12/linux-jiao-ben/" itemprop="url">
          <h2 class="card-text--title text-ellipsis">linux脚本</h2>
        </a>
      
      <div class="card-text--row">Older</div>
    </div>
  </article>
</div>
          
        </nav>
      

      <section class="page-message-container layout-padding">
        


  
  
    <div class="valine-container comments-container content-padding--primary soft-size--large soft-style--box">
      <div id="valine_thread" class="valine-thread"></div>
    </div>
    <script type="text/javascript" src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <script type="text/javascript" src='//unpkg.com/valine/dist/Valine.min.js'></script>
    <script type="text/javascript">
      new Valine({
        el: "#valine_thread",
        appId: "yEts8yIOQopn7imcDAmwhlNi-gzGzoHsz",
        appKey: "nyOyHJdsDGQh3UI0TdNdLLnN",
        avatar: "mm",
        placeholder: "随便说点什么叭～",
        notify: true,
        visitor: true,
        pageSize: 10,
      });
    </script>
  

  
  


      </section>
    </div>
    <div class="widget-info">
      <section class="widget-calendar widget-item layout-margin content-padding--primary soft-size--large soft-style--box">
  <div class="widget-body">
	<div id="calendar"></div>
  </div>
</section>

      <section class="widget-categorys widget-item layout-margin content-padding--primary soft-size--large soft-style--box">
  <div class="widget-title">
    <svg class="icon icon-categories" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M900.3614811 257.09082106h-339.81629553l-67.96326003-101.9448889c-19.41807444-29.12711113-48.54518557-43.69066667-82.52681443-43.69066667H123.6385189c-53.39970333 0-97.09036999 43.69066667-97.09037113 97.09036999v582.54222222c0 53.39970333 43.69066667 97.09036999 97.09037113 97.09037002h776.7229622c53.39970333 0 97.09036999-43.69066667 97.09037113-97.09037002V354.18119104c0-53.39970333-43.69066667-97.09036999-97.09037113-97.09036998z m-97.09036999 242.72592554H220.72888889c-24.27259221 0-48.54518557-24.27259221-48.54518556-48.54518556s24.27259221-48.54518557 48.54518556-48.54518444h582.54222222c24.27259221 0 48.54518557 24.27259221 48.54518556 48.54518444s-24.27259221 48.54518557-48.54518556 48.54518556z" fill="currentColor"></path>
</svg>
    <span>CATEGORYS</span>
  </div>
  <div class="widget-body">
    <ul class="categorys-list">
      
        <li class="categorys-list-item">
          <a href="/categories/%E6%8A%80%E6%9C%AF/">
            技术 (11)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E7%AE%97%E6%B3%95/">
            算法 (15)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E5%B7%A5%E5%85%B7/">
            工具 (3)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E9%97%AE%E9%A2%98/">
            问题 (8)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E8%BD%AF%E4%BB%B6/">
            软件 (31)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/">
            中间件 (26)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E5%90%8E%E7%AB%AF/">
            后端 (1)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/java/">
            java (4)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E6%95%B0%E6%8D%AE/">
            数据 (5)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/linux/">
            linux (3)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/web/">
            web (1)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E7%89%9B%E8%B7%AF%E6%9D%91/">
            牛路村 (1)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E9%97%B2%E8%B0%88/">
            闲谈 (5)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E5%89%8D%E7%AB%AF/">
            前端 (1)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E5%BE%AE%E4%BF%A1/">
            微信 (1)
          </a>
        </li>
      
        <li class="categorys-list-item">
          <a href="/categories/%E8%8B%A5%E4%BE%9D/">
            若依 (1)
          </a>
        </li>
      
    </ul>
  </div>
</section>

      <section class="widget-tags widget-item  layout-margin content-padding--primary soft-size--large soft-style--box">
  <div class="widget-title">
    <svg class="icon icon-tags" viewBox="0 0 1098 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M283.42180005 272q0-28.38857157-20.09142843-48.48000001t-48.47999998-20.09142842-48.48000002 20.09142842-20.09142846 48.48000001 20.09142846 48.48 48.48000002 20.09142843 48.47999998-20.09142843 20.09142843-48.48zM855.0332285 580.57142843q0 28.38857157-19.81714313 48.2057147l-263.03999997 263.58857157q-20.9142853 19.81714313-48.75428534 19.81714312-28.38857157 0-48.20571468-19.81714312l-383.04-383.58857157q-20.36571468-19.81714313-34.55999999-54.10285688t-14.19428534-62.6742853l0-222.85714313q0-27.84000002 20.36571469-48.20571469t48.2057147-20.36571466l222.85714313 0q28.38857157 0 62.6742853 14.19428529t54.65142842 34.55999999l383.04000001 382.49142843q19.81714313 20.9142853 19.81714314 48.75428532zM1060.74751475 580.57142843q0 28.38857157-19.81714313 48.2057147l-263.04 263.58857157q-20.9142853 19.81714313-48.75428531 19.81714312-19.26857155 0-31.61142843-7.47428531t-28.38857159-24.13714314l251.79428534-251.7942853q19.81714313-19.81714313 19.81714308-48.20571469 0-27.84000002-19.81714308-48.75428531l-383.04000001-382.49142845q-20.36571468-20.36571468-54.65142842-34.55999999t-62.67428532-14.19428534l120 0q28.38857157 0 62.67428532 14.19428534t54.65142842 34.55999999l383.03999998 382.49142845q19.81714313 20.9142853 19.81714314 48.75428531z" fill="currentColor"></path>
</svg>
    <span>TAGS</span>
  </div>
  <div class="widget-body">
    <div class="tags-cloud">
      <a href="/tags/crontab/" style="font-size: 10px;" class="tags-cloud-0">crontab</a> <a href="/tags/docker/" style="font-size: 20px;" class="tags-cloud-10">docker</a> <a href="/tags/elasticsearch/" style="font-size: 10px;" class="tags-cloud-0">elasticsearch</a> <a href="/tags/fastdfs/" style="font-size: 10px;" class="tags-cloud-0">fastdfs</a> <a href="/tags/git/" style="font-size: 10px;" class="tags-cloud-0">git</a> <a href="/tags/go/" style="font-size: 12.5px;" class="tags-cloud-3">go</a> <a href="/tags/hexo/" style="font-size: 10px;" class="tags-cloud-0">hexo</a> <a href="/tags/idea/" style="font-size: 10px;" class="tags-cloud-0">idea</a> <a href="/tags/jvm/" style="font-size: 11.25px;" class="tags-cloud-1">jvm</a> <a href="/tags/kafka/" style="font-size: 11.25px;" class="tags-cloud-1">kafka</a> <a href="/tags/linux/" style="font-size: 15px;" class="tags-cloud-5">linux</a> <a href="/tags/maven/" style="font-size: 10px;" class="tags-cloud-0">maven</a> <a href="/tags/minio/" style="font-size: 11.25px;" class="tags-cloud-1">minio</a> <a href="/tags/mysql/" style="font-size: 13.75px;" class="tags-cloud-4">mysql</a> <a href="/tags/nginx/" style="font-size: 12.5px;" class="tags-cloud-3">nginx</a> <a href="/tags/node/" style="font-size: 10px;" class="tags-cloud-0">node</a> <a href="/tags/oracle/" style="font-size: 10px;" class="tags-cloud-0">oracle</a> <a href="/tags/pulsar/" style="font-size: 10px;" class="tags-cloud-0">pulsar</a> <a href="/tags/rabbitmq/" style="font-size: 17.5px;" class="tags-cloud-8">rabbitmq</a> <a href="/tags/redis/" style="font-size: 16.25px;" class="tags-cloud-6">redis</a> <a href="/tags/redis-%E4%BA%8B%E5%8A%A1/" style="font-size: 10px;" class="tags-cloud-0">redis,事务</a> <a href="/tags/rocketmq/" style="font-size: 17.5px;" class="tags-cloud-8">rocketmq</a> <a href="/tags/shell/" style="font-size: 10px;" class="tags-cloud-0">shell</a> <a href="/tags/spring/" style="font-size: 10px;" class="tags-cloud-0">spring</a> <a href="/tags/tomcat/" style="font-size: 10px;" class="tags-cloud-0">tomcat</a> <a href="/tags/vim/" style="font-size: 10px;" class="tags-cloud-0">vim</a> <a href="/tags/yml/" style="font-size: 10px;" class="tags-cloud-0">yml</a> <a href="/tags/zookeeper/" style="font-size: 10px;" class="tags-cloud-0">zookeeper</a> <a href="/tags/%E4%B8%87%E5%B9%B4%E5%8F%B0/" style="font-size: 10px;" class="tags-cloud-0">万年台</a> <a href="/tags/%E4%B8%AD%E9%97%B4%E4%BB%B6/" style="font-size: 18.75px;" class="tags-cloud-9">中间件</a> <a href="/tags/%E4%BA%8B%E5%8A%A1/" style="font-size: 10px;" class="tags-cloud-0">事务</a> <a href="/tags/%E5%8A%A0%E5%AF%86/" style="font-size: 13.75px;" class="tags-cloud-4">加密</a> <a href="/tags/%E5%93%A8%E5%85%B5/" style="font-size: 10px;" class="tags-cloud-0">哨兵</a> <a href="/tags/%E5%B7%A5%E5%85%B7/" style="font-size: 11.25px;" class="tags-cloud-1">工具</a> <a href="/tags/%E5%B8%B8%E7%94%A8%E7%AE%97%E6%B3%95/" style="font-size: 16.25px;" class="tags-cloud-6">常用算法</a> <a href="/tags/%E5%B9%B6%E5%8F%91/" style="font-size: 10px;" class="tags-cloud-0">并发</a> <a href="/tags/%E6%96%87%E4%BB%B6%E5%AD%98%E5%82%A8/" style="font-size: 11.25px;" class="tags-cloud-1">文件存储</a> <a href="/tags/%E7%B4%A2%E5%BC%95/" style="font-size: 10px;" class="tags-cloud-0">索引</a> <a href="/tags/%E9%94%81%E6%9C%BA%E5%88%B6/" style="font-size: 10px;" class="tags-cloud-0">锁机制</a> <a href="/tags/%E9%97%AE%E9%A2%98/" style="font-size: 10px;" class="tags-cloud-0">问题</a>
    </div>
  </div>
</section>
    </div>
  </article>
</div>
<script>
	//解决中文转义无法跳转锚点问题
	var blog = document.querySelector("#blog-content");
	var content = blog.innerHTML;
	var regExp2 = /<h([1-6]) id=\"(\S*?)\">/g;
	var	data = content.replace(regExp2, function(word,i){
		var ws = word.split("\"");
			return ws[0]+"\""+encodeURIComponent(ws[1])+"\""+ws[2];
		},"g");
	blog.innerHTML = data;
</script>

    <!-- footer container -->
<footer id="footer" class="footer">
  <div class="footer-container">
    
    <div class="social-icons">
      
        
          <a href="https://music.163.com/#/user/home?id=444731906" class="soft-size--primary soft-style--box" target="_blank" rel="noopener noreferrer">
            <svg class="icon icon-<%= icon %>" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <path d="M952.17867 503.263237a341.054956 341.054956 0 0 0-56.853199-113.706399 408.604266 408.604266 0 0 0-109.723463-98.352823 304.662484 304.662484 0 0 0-143.257215-42.077792L621.305897 170.238394a40.343287 40.343287 0 0 1 10.792472-36.392472 56.88532 56.88532 0 0 1 36.392472-18.758344 102.785445 102.785445 0 0 1 56.853199 18.758344c6.263488 3.404768 10.792472 9.090088 17.05596 13.073024a57.335006 57.335006 0 0 0 82.999247-70.632873 66.521455 66.521455 0 0 0-22.74128-27.848432 237.691343 237.691343 0 0 0-89.262735-43.202007A170.559598 170.559598 0 0 0 625.288833 6.42409a167.026349 167.026349 0 0 0-60.836135 37.516688 164.328231 164.328231 0 0 0-40.921456 51.713927 156.908407 156.908407 0 0 0-8.54404 113.706399l13.651192 52.870264a284.298118 284.298118 0 0 0-158.064743 109.209535 256.963614 256.963614 0 0 0-43.202007 156.908407 248.419573 248.419573 0 0 0 13.651192 74.487327 205.281807 205.281807 0 0 0 80.718695 104.616312 185.945295 185.945295 0 0 0 136.447679 25.696361 193.879046 193.879046 0 0 0 156.330238-196.705646L708.802008 503.263237c-11.948808-46.060728-24.443664-91.543287-35.814304-137.025847a182.283563 182.283563 0 0 1 47.763112 18.180176 316.611292 316.611292 0 0 1 47.763111 34.690088A239.907654 239.907654 0 0 1 840.752823 529.987453a284.169636 284.169636 0 0 1 0 158.064743 252.241907 252.241907 0 0 1-21.584943 51.167879 308.741782 308.741782 0 0 1-168.279047 144.542033 387.918695 387.918695 0 0 1-130.184191 23.319448 332.607277 332.607277 0 0 1-155.206022-37.516688A367.233124 367.233124 0 0 1 194.87478 672.666499a373.014806 373.014806 0 0 1-20.460727-180.806022A366.173149 366.173149 0 0 1 406.869762 198.536512a57.399247 57.399247 0 0 0 13.073023-100.055207 76.189711 76.189711 0 0 0-63.662735-3.404768A479.815307 479.815307 0 0 0 68.705646 436.163614a488.905395 488.905395 0 0 0 129.027855 450.84266 454.857716 454.857716 0 0 0 248.997741 131.886574 470.885822 470.885822 0 0 0 138.117942 0A454.889837 454.889837 0 0 0 773.042911 952.949561a427.523212 427.523212 0 0 0 170.559598-209.232622 417.276788 417.276788 0 0 0 22.74128-109.209536 378.089837 378.089837 0 0 0-14.165119-131.244166z m-412.747804 118.845671a72.174655 72.174655 0 0 1-56.8532-10.792471 98.352823 98.352823 0 0 1-37.516687-61.382184 170.68808 170.68808 0 0 1 0-65.943287 133.042911 133.042911 0 0 1 33.533751-63.662735 181.35207 181.35207 0 0 1 80.718695-46.606776l39.219072 148.364367a204.189711 204.189711 0 0 1 5.107152 26.146048 79.594479 79.594479 0 0 1-64.208783 73.844918z"></path>
  </svg>
          </a>
        
      
        
          <a href="https://www.zhihu.com" class="soft-size--primary soft-style--box" target="_blank" rel="noopener noreferrer">
            <svg t="1587373160860" class="icon icon-zhihu" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M544.949 561.422s0-71.387-34.779-75.050c-34.779-3.663-142.775 0-142.775 0v-219.654h161.078s-1.83-73.219-32.949-73.219h-261.755l43.93-117.148s-65.897 3.663-89.692 45.761-98.844 252.604-98.844 252.604 25.627 10.983 67.726-20.134c42.101-31.116 56.743-86.033 56.743-86.033l76.879-3.663 1.83 223.316s-133.621-1.83-161.078 0c-27.457 1.83-42.101 75.050-42.101 75.050h203.182s-18.307 124.47-69.557 214.164c-53.085 89.692-151.929 161.078-151.929 161.078s71.387 29.287 140.947-10.983c69.557-42.101 120.811-223.316 120.811-223.316l162.912 203.182s14.643-97.013-1.83-124.47c-18.307-27.457-113.49-137.283-113.49-137.283l-42.101 36.607 29.287-120.811h177.552zM587.050 188.010l-1.83 660.793h65.897l23.795 82.37 115.321-82.37h162.912v-660.793h-366.091zM879.92 775.584h-76.879l-97.013 75.050-21.965-75.050h-20.134v-512.527h215.991v512.527z"></path>
</svg>
          </a>
        
      
        
          <a href="https://gitee.com/RocPengHua" class="soft-size--primary soft-style--box" target="_blank" rel="noopener noreferrer">
            <svg class="icon icon-<%= icon %>" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <path d="M512 1024C229.248 1024 0 794.752 0 512S229.248 0 512 0s512 229.248 512 512-229.248 512-512 512z m259.168-568.896h-290.752a25.28 25.28 0 0 0-25.28 25.28l-0.032 63.232c0 13.952 11.296 25.28 25.28 25.28h177.024a25.28 25.28 0 0 1 25.28 25.28v12.64a75.84 75.84 0 0 1-75.84 75.84h-240.224a25.28 25.28 0 0 1-25.28-25.28v-240.192a75.84 75.84 0 0 1 75.84-75.84h353.92a25.28 25.28 0 0 0 25.28-25.28l0.064-63.2a25.312 25.312 0 0 0-25.28-25.312H417.184a189.632 189.632 0 0 0-189.632 189.6v353.952c0 13.952 11.328 25.28 25.28 25.28h372.928a170.656 170.656 0 0 0 170.656-170.656v-145.376a25.28 25.28 0 0 0-25.28-25.28z" p-id="1954"></path>
  </svg>
          </a>
        
      
        
          <a href="https://github.com/RocPengHua" class="soft-size--primary soft-style--box" target="_blank" rel="noopener noreferrer">
            <svg class="icon icon-github" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M64.6 512c0 195.6 125.4 361.9 300.1 422.9 23.5 5.9 19.9-10.8 19.9-22.2v-77.6c-135.8 15.9-141.3-74-150.5-89-18.5-31.5-61.9-39.5-49-54.5 31-15.9 62.5 4 98.9 58 26.4 39.1 77.9 32.5 104.1 26 5.7-23.5 17.9-44.5 34.7-60.9-140.7-25.2-199.4-111.1-199.4-213.3 0-49.5 16.4-95.1 48.4-131.8-20.4-60.6 1.9-112.4 4.9-120.1 58.2-5.2 118.5 41.6 123.3 45.3 33.1-8.9 70.8-13.7 112.9-13.7 42.4 0 80.3 4.9 113.5 13.9 11.3-8.6 67.3-48.8 121.4-43.9 2.9 7.7 24.7 58.3 5.5 118.1 32.5 36.8 49 82.8 49 132.4 0 102.3-59 188.3-200.2 213.2 23.5 23.3 38.1 55.5 38.1 91.1v112.7c0.8 9 0 17.9 15.1 17.9C832.7 877 960.4 709.4 960.4 512.1c0-247.5-200.6-447.9-447.9-447.9C265 64.1 64.6 264.5 64.6 512z"></path>
</svg>
          </a>
        
      
        
          <a href="https://twitter.com/guanquanhong" class="soft-size--primary soft-style--box" target="_blank" rel="noopener noreferrer">
            <svg class="icon icon-twitter" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M962.285714 233.142857q-38.285714 56-92.571429 95.428571 0.571429 8 0.571429 24 0 74.285714-21.714286 148.285714t-66 142-105.428571 120.285714-147.428571 83.428571-184.571429 31.142857q-154.857143 0-283.428571-82.857143 20 2.285714 44.571429 2.285714 128.571429 0 229.142857-78.857143-60-1.142857-107.428571-36.857143t-65.142857-91.142857q18.857143 2.857143 34.857143 2.857143 24.571429 0 48.571429-6.285714-64-13.142857-106-63.714286t-42-117.428571l0-2.285714q38.857143 21.714286 83.428571 23.428571-37.714286-25.142857-60-65.714286t-22.285714-88q0-50.285714 25.142857-93.142857 69.142857 85.142857 168.285714 136.285714t212.285714 56.857143q-4.571429-21.714286-4.571429-42.285714 0-76.571429 54-130.571429t130.571429-54q80 0 134.857143 58.285714 62.285714-12 117.142857-44.571429-21.142857 65.714286-81.142857 101.714286 53.142857-5.714286 106.285714-28.571429z"></path>
</svg>
          </a>
        
      
    </div>
     
    <p>&copy; 2024 <a href="/" target="_blank">RocPengHua</a></p>

    

    <p>Powered by <a href="https://hexo.io" target="_blank" rel="noopener noreferrer">Hexo</a> Theme - <a href="https://github.com/miiiku/flex-block" target="_blank" rel="noopener noreferrer author">flex-block</a></p>

    <p>
      <a href="javascript:;" id="theme-light">🌞 浅色</a>
      <a href="javascript:;" id="theme-dark">🌛 深色</a>
      <a href="javascript:;" id="theme-auto">🤖️ 自动</a>
    </p>
  </div>
</footer>
  </div>

  <div class="back-to-top-fixed soft-size--round soft-style--box">
    <svg class="icon icon-back-to-top" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
      <path d="M725.333333 426.666667c-12.8 0-21.333333-4.266667-29.866667-12.8l-213.333333-213.333333c-17.066667-17.066667-17.066667-42.666667 0-59.733333s42.666667-17.066667 59.733333 0l213.333333 213.333333c17.066667 17.066667 17.066667 42.666667 0 59.733333C746.666667 422.4 738.133333 426.666667 725.333333 426.666667z"></path>
      <path d="M298.666667 426.666667c-12.8 0-21.333333-4.266667-29.866667-12.8-17.066667-17.066667-17.066667-42.666667 0-59.733333l213.333333-213.333333c17.066667-17.066667 42.666667-17.066667 59.733333 0s17.066667 42.666667 0 59.733333l-213.333333 213.333333C320 422.4 311.466667 426.666667 298.666667 426.666667z"></path>
      <path d="M512 896c-25.6 0-42.666667-17.066667-42.666667-42.666667L469.333333 170.666667c0-25.6 17.066667-42.666667 42.666667-42.666667s42.666667 17.066667 42.666667 42.666667l0 682.666667C554.666667 878.933333 537.6 896 512 896z"></path>
    </svg>
  </div>

  
  <!-- aplayer -->


<!-- dplayer -->




  


  


  <!-- Baidu Analytics START -->
  <script>
    var _hmt = _hmt || [];
    (function () {
      if (window.location.hostname === "localhost" || window.location.hostname.startsWith("192.168")) {
        return console.log("本地调试");
      }
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?true";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>
  <!-- Baidu Analytics End -->

  




<script src="/js/script.js"></script>


  
  <link rel="stylesheet" href="/lib/aplayer/APlayer.min.css">
<script type="text/javascript" src="/lib/aplayer/APlayer.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="/js/search.js"></script>

<!-- Calendar -->

    <script src="/js/calendar.js"></script>
    <script src="/js/languages.js"></script>
    <script type="text/javascript">
        $(function() {
            $('#calendar').aCalendar(
                'zh-CN',
                {single:false, root:'calendar/'}
            );
        });
    </script>

<!-- 尾部用户自定义相关内容 -->
<div id="aplayer"></div>
<script type="text/javascript">

	/*获取音乐*/
	$.get("https://api.i-meto.com/meting/api?server=netease&type=playlist&id=3778678&r=0.37201068616290645", function(result){
		if(result && result.code  == 50000){
			console.log(result.msg);
			return;
		}
	    const ap = new APlayer({
	    container: document.getElementById('aplayer'),
	    global:true,
	    id:'3778678',
	    server: 'netease',
	    type: 'paylist',
	    fixed: true,
	    preload: 'none',
	    theme: '#ffa500',
	    autoplay: false,
	    audio: result
	  });
	});










	/*图片放大js*/
	function createImgEventFullScreen() {
        var imgs = $(".post-container").find("img");
        for (var i = 0; i < imgs.length; i++) {
            // $(imgs[i]).click(createCover(imgs[i]));
            imgs[i].onclick = function (e) {
                var src = e.srcElement.currentSrc;
                var _this = $(this);
                console.log(_this);
                createCover(src,_this);
            }
        }
        function createCover(src,_this) {
            console.log(_this);
            console.log(src);
            var cover = $("<div id='outerDiv'  style='position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:5;width:100%;height:100%;display:none;'><div id='innerDiv' style='position:absolute;'><img  id='bigImg' style='border:5px solid #fff;' src=''/></div></div>");
            $("#outerDiv").remove();
            $("body").append(cover);
            imgShow("#outerDiv", "#innerDiv", "#bigImg", _this,src);

        }
    }
    function imgShow(outerDiv, innerDiv, bigImg, _this,src) {
        //var src = _this.attr("src"); //获取当前点击的common-img元素中的src属性
        $(bigImg).attr("src", src); //设置#bigImg元素的src属性

        /*获取当前点击图片的真实大小，并显示弹出层及大图*/
        $("<img/>").attr("src", src).on('load',function () {
            var windowW = $(window).width(); //获取当前窗口宽度
            var windowH = $(window).height(); //获取当前窗口高度
            var realWidth = this.width; //获取图片真实宽度
            var realHeight = this.height; //获取图片真实高度
            var imgWidth, imgHeight;
            var scale = 0.8; //缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

            if (realHeight > windowH * scale) { //判断图片高度
                imgHeight = windowH * scale; //如大于窗口高度，图片高度进行缩放
                imgWidth = imgHeight / realHeight * realWidth; //等比例缩放宽度
                if (imgWidth > windowW * scale) { //如宽度仍大于窗口宽度
                    imgWidth = windowW * scale; //再对宽度进行缩放
                }
            } else if (realWidth > windowW * scale) { //如图片高度合适，判断图片宽度
                imgWidth = windowW * scale; //如大于窗口宽度，图片宽度进行缩放
                imgHeight = imgWidth / realWidth * realHeight; //等比例缩放高度
            } else { //如果图片真实高度和宽度都符合要求，高宽不变
                imgWidth = realWidth;
                imgHeight = realHeight;
            }
            $(bigImg).css("width", imgWidth); //以最终的宽度对图片缩放

            var w = (windowW - imgWidth) / 2; //计算图片与窗口左边距
            var h = (windowH - imgHeight) / 2; //计算图片与窗口上边距
            $(innerDiv).css({ "top": h, "left": w }); //设置#innerDiv的top和left属性
            //console.log('****')
            $(outerDiv).fadeIn("fast"); //淡入显示#outerDiv
        });

        $(outerDiv).click(function () { //再次点击淡出消失弹出层
            $(this).fadeOut("fast");
        });
    }
    setTimeout(function () {
        createImgEventFullScreen();
    }, 1000)
</script>
<style>
.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body{
	width: 0px!important
}
.aplayer.aplayer-narrow .aplayer-body, .aplayer.aplayer-narrow .aplayer-pic {
	width: 0px!important
}
</style>
</body>
</html>